/**
 * This file is part of the NatCrackerToolbox.
 * 
 * Copyright (C) 2009 - 2011 Peerialism Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 **/
package com.peerialism.natcracker.common;

public class TraversalStrategy {
	private PortMappingTechnique uploaderStrategy = PortMappingTechnique.NONE;
	private PortMappingTechnique downloaderStrategy = PortMappingTechnique.NONE;
	private boolean portScanDownloader = false;
	private boolean portScanUploader = false;
	private boolean canConnect = true;
	private double successProbability = 1.0;

	public TraversalStrategy(PortMappingTechnique uploaderStrategy,
			PortMappingTechnique downloaderStrategy, double successProbability) {
		super();
		this.uploaderStrategy = uploaderStrategy;
		this.downloaderStrategy = downloaderStrategy;
		this.successProbability = successProbability;
	}

	public TraversalStrategy(boolean canConnect) {
		this.canConnect = canConnect;
		successProbability = 0;
	}

	public PortMappingTechnique getUploaderStrategy() {
		return uploaderStrategy;
	}

	public PortMappingTechnique getDownloaderStrategy() {
		return downloaderStrategy;
	}

	public boolean canConnect() {
		return canConnect;
	}

	@Override
	public String toString() {
		return "CanConnect:" + canConnect + ",UP:" + uploaderStrategy + ",DW:" + downloaderStrategy;
	}

	public boolean isPortScanDownloader() {
		return portScanDownloader;
	}

	public void setPortScanDownloader(boolean portScanDownloader) {
		this.portScanDownloader = portScanDownloader;
	}

	public boolean isPortScanUploader() {
		return portScanUploader;
	}

	public void setPortScanUploader(boolean portScanUploader) {
		this.portScanUploader = portScanUploader;
	}

	public double getSuccessProbability() {
		return successProbability;
	}

	public void setSuccessProbability(double successProbability) {
		this.successProbability = successProbability;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
		+ ((downloaderStrategy == null) ? 0 : downloaderStrategy.hashCode());
		result = prime * result + ((uploaderStrategy == null) ? 0 : uploaderStrategy.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TraversalStrategy other = (TraversalStrategy) obj;
		if (downloaderStrategy == null) {
			if (other.downloaderStrategy != null)
				return false;
		} else if (!downloaderStrategy.equals(other.downloaderStrategy))
			return false;
		if (uploaderStrategy == null) {
			if (other.uploaderStrategy != null)
				return false;
		} else if (!uploaderStrategy.equals(other.uploaderStrategy))
			return false;
		return true;
	}
}
